package com.founding.rabbitmq.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

//编写工具类方便获取连接对象
public class ConnectionUtil {
    public static Connection getConnection() throws Exception {
        //创建连接工厂
        ConnectionFactory connectionFactory = new ConnectionFactory();
        //主机地址，默认localhost  但我的在虚拟机中192.168.200.130
        connectionFactory.setHost("192.168.200.130");
        //连接端口，默认5672
        connectionFactory.setPort(5672);
        //虚拟主机名称；默认为/
        connectionFactory.setVirtualHost("/itcast");
        //连接用户名；默认为guest
        connectionFactory.setUsername("heima");
        //连接密码，默认guest
        connectionFactory.setPassword("itcast");

        //创建连接
        Connection connection = connectionFactory.newConnection();
        return connection;
    }
}
